<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no" />
    <link type="text/css" rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/zepto.alert.css" />
    <link type="text/css" rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/wish/index.css" />

    <script type='text/javascript' src='{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js'></script>

    <script type='text/javascript' src='{$Think.config.RESOURCEURL}wx_assets/js/json2.js'></script>

    <script src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js" type="text/javascript"></script>

    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js" type="text/javascript"></script>

</head>
<body>
        <ul class="addrEditbox">
            <li><input type="text" value="{$fullName}" id="fullName" placeholder="姓名"></li>
            <li><input type="tel" value="{$phone}" id="phone" placeholder="电话"></li>
            <li><input type="text" value="{$address}" id="address" placeholder="详细地址"></li>
        </ul>
        <a class="order-btn address-btn" id="BtnSave">保存收货地址</a>
        <script type="text/javascript">
            var baseUrl = '{$Think.config.SERVER_HOST}';
            var wish = {
                init: function() {
                    this._initEvent();
                },
                _save: function() {
                    var customerId = $.util.getParam("customerId");
                    var userName = $.util.getParam("userName");
                    var postUrl = baseUrl + 'call.json?customerId={$customerId}';
                    if(!$("#fullName").val()){
                        $.util.alert('请输入收货人姓名！');
                        return false;
                    }
                    if(!$("#phone").val()){
                        $.util.alert('请输入收货人联系电话！');
                        return false;
                    }
                    if(!$("#address").val()){
                        $.util.alert('请输入收货人详细地址！');
                        return false;
                    }
                    var data = {
                        fullName:$("#fullName").val(),
                        phone:$("#phone").val(),
                        address:$("#address").val()
                    };
                    $.ajax({
                        url: postUrl,
                        dataType: "json",
                        type: "POST",
                        data: {
                            module: 'wish',
                            method: 'saveAddress',
                            userName:'{$userName}',
                            params: JSON.stringify(data)
                        },
                        success: function(data) {
                            var actId="{$actId}";
                            if(!data.code) {
                                location.href = baseUrl + 'call.html?customerId={$customerId}&module=wish&method=createWish&params={"actId":"'+actId+'"}';
                            }
                        }
                    });
                },
                _initEvent: function() {
                    var me = this;
                    $("#BtnSave").click(function() {
                        me._save();
                    });
                }
            }
            wish.init();
        </script>
</body>
</html>
